package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.HybrankDetail;
import com.stylefeng.guns.modular.system.service.IHybrankDetailService;
import com.stylefeng.guns.modular.system.warpper.HyBrankDetailWarpper;

/**
 * hydetail控制器
 *
 * @author fengshuonan
 * @Date 2018-06-01 13:51:16
 */
@Controller
@RequestMapping("/hybrankDetail")
public class HybrankDetailController extends BaseController {

    private String PREFIX = "/system/hybrankDetail/";

    @Autowired
    private IHybrankDetailService hybrankDetailService;

    /**
     * 跳转到hydetail首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "hybrankDetail.html";
    }

    /**
     * 跳转到添加hydetail
     */
    @RequestMapping("/hybrankDetail_add")
    public String hybrankDetailAdd() {
        return PREFIX + "hybrankDetail_add.html";
    }

    /**
     * 跳转到修改hydetail
     */
    @RequestMapping("/hybrankDetail_update/{hybrankDetailId}")
    public String hybrankDetailUpdate(@PathVariable Integer hybrankDetailId, Model model) {
        HybrankDetail hybrankDetail = hybrankDetailService.selectById(hybrankDetailId);
        model.addAttribute("item",hybrankDetail);
        LogObjectHolder.me().set(hybrankDetail);
        return PREFIX + "hybrankDetail_edit.html";
    }

    /**
     * 获取hydetail列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String dm,String date) {
    	Page<HybrankDetail> page = new PageFactory<HybrankDetail>().defaultPage();
    	List<Map<String, Object>> branks = hybrankDetailService.selectDetailMaps(page,dm,date);
    	page.setRecords((List<HybrankDetail>) new HyBrankDetailWarpper(branks).warp());
        return super.packForBT(page);
    }

    /**
     * 新增hydetail
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(HybrankDetail hybrankDetail) {
        hybrankDetailService.insert(hybrankDetail);
        return SUCCESS_TIP;
    }

    /**
     * 删除hydetail
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer hybrankDetailId) {
        hybrankDetailService.deleteById(hybrankDetailId);
        return SUCCESS_TIP;
    }

    /**
     * 修改hydetail
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(HybrankDetail hybrankDetail) {
        hybrankDetailService.updateById(hybrankDetail);
        return SUCCESS_TIP;
    }

    /**
     * hydetail详情
     */
    @RequestMapping(value = "/detail/{hybrankDetailId}")
    @ResponseBody
    public Object detail(@PathVariable("hybrankDetailId") Integer hybrankDetailId) {
        return hybrankDetailService.selectById(hybrankDetailId);
    }
}
